package com.youxue.teachin;

import android.app.Application;
import android.content.Context;
import com.Navigator;
import com.hybrid.config.GlobalConfig;
import com.hybrid.config.WVAppParams;
import com.library.rest.ApiServiceManager;
import com.library.rest.retrofiturlmanager.RetrofitUrlManager;
import com.library.rest.utils.Uttid;
import com.library.uiframework.utils.ContextUtils;
import com.library.uiframework.utils.DisplayUtils;
import com.library.uiframework.utils.MToast;
import com.youxue.teachin.common.api.UrlHelper;
import com.youxue.teachin.common.utils.AppUtils;
import com.youxue.teachin.jpush.JpushManager;
import com.youxue.teachin.user.userSystem.UserSystem;
import com.youxue.teachin.youmen.UMenUtils;
import com.youxue.teachin.youmen.UMenUtils.UmenConfig;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-10-04 21:15
 * @version: 9.1.0
 */
public class TeachINApplication extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        //MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        initMast();
    }

    private void initMast() {
        nomeInit();
        webInit();
        initAPI();

        initJpush();
        initUmen();
    }

    private void initJpush(){
        JpushManager.init(this, BuildConfig.DEBUG);
    }


    private void initUmen() {
        //Log.e("致伟", this.getClass().getSimpleName() + " initUmen: =" + YouMenUtils.getDeviceInfo(this));
        UmenConfig umenConfig = new UmenConfig();
        umenConfig.DEBUG = BuildConfig.DEBUG;
        UMenUtils.init(this, umenConfig);
    }

    private void nomeInit() {
        ContextUtils.setContext(this);
        Navigator.init(this, "teachin", "page");
        DisplayUtils.init();
        MToast.getInstance().init(this);
    }

    private void webInit() {
        WVAppParams params = new WVAppParams();
        params.appName = getString(R.string.app_name);
        params.appVersion = AppUtils.getVersion(this);
        params.width = getResources().getDisplayMetrics().widthPixels;
        params.height = getResources().getDisplayMetrics().heightPixels;
        GlobalConfig.getInstance().initParam(params);
    }

    private void initAPI() {
        UserSystem.getInstance().init();

        //api
        String deviceID = Uttid.getUttid(this);
        ApiServiceManager.setDebug(BuildConfig.DEBUG);
        ApiServiceManager.deviceNo = deviceID;

        //将每个 BaseUrl 进行初始化,运行时可以随时改变 DOMAIN_NAME 对应的值,从而达到改变 BaseUrl 的效果
        RetrofitUrlManager.getInstance().putDomain(UrlHelper.TEACHIN_DOMAIN_NAME, UrlHelper.APP_TEACHEIN_DOMAIN);
        ApiServiceManager.init(UrlHelper.APP_DEFAULT_DOMAIN);


    }
}
